package com.hao.study.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hao.study.entity.Notice;
import com.hao.study.service.NoticeService;
import com.hao.study.mapper.NoticeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Administrator
* @description 针对表【b_notice】的数据库操作Service实现
* @createDate 2024-06-12 22:13:32
*/
@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice>
    implements NoticeService{

    @Autowired
    NoticeMapper mapper;

    @Override
    public void createNotice(Notice notice) {
        System.out.println(notice);
        notice.setCreateTime(String.valueOf(System.currentTimeMillis()));
        mapper.insert(notice);
    }

    @Override
    public PageInfo<Notice> getList(Integer pageNum, Integer pageSize, String keyWord) {
        PageHelper.startPage(pageNum,pageSize);
        QueryWrapper<Notice> queryWrapper =new QueryWrapper<>();
        if (StringUtils.isNotBlank(keyWord)){
            queryWrapper.like("title",keyWord);
        }
        List<Notice> list = mapper.selectList(queryWrapper);
        return PageInfo.of(list);
    }

    @Override
    public void deleteNotice(String id) {
        mapper.deleteById(id);
    }

    @Override
    public void updateNotice(Notice notice) {
        mapper.updateById(notice);
    }
}




